package com.bauer.java.spring;

import javax.servlet.AsyncContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.io.IOException;

/**
 * @Author ：rui.wei
 * @Date ：Created in 10:48 2019/7/31
 * @Description：
 */
@WebServlet(asyncSupported = true, value = "/simpleAsync")
public class ServletAsyncController extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        AsyncContext asyncContext = req.startAsync();
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    Thread.sleep(10000);
                    resp.getWriter().write("hello sync");
                } catch (Exception e) {
                }
                asyncContext.complete();
            }
        }).start();
    }
}
